from models.channel import *
from models import db
from datetime import datetime


# 用户基本信息
class User(db.Model):
    __tablename__ = 'user_basic_tb'
    class STATUS:
        ENABLE = 1
        DISABLE = 0
    uid = db.Column(db.Integer, primary_key=True, autoincrement=True,doc='用户ID')
    mobile = db.Column(db.String(11), doc='手机号')
    password = db.Column(db.String(520), doc='密码')
    uname = db.Column(db.String(32), doc='昵称')
    profile_photo = db.Column(db.String(256), nullable=True, doc='头像')
    created_time = db.Column(db.DateTime,default=datetime.now(),doc='创建时间')
    gender = db.Column(db.String(2),default=0,doc='0女 1男')

    last_login = db.Column(db.DateTime,default=datetime.now(), doc='最后登录时间')
    is_media = db.Column(db.Boolean, default=False, doc='是否是自媒体')
    is_verified = db.Column(db.Boolean, default=False, doc='是否实名认证')
    introduction = db.Column(db.String(128),default='此人很懒,什么都没留下', doc='简介')
    certificate = db.Column(db.String(64), default='已认证',doc='认证')
    article_count = db.Column(db.Integer, default=0, doc='发帖数')
    following_count = db.Column(db.Integer, default=0, doc='关注的人数')
    fans_count = db.Column(db.Integer, default=0, doc='被关注的人数（粉丝数）')
    like_count = db.Column(db.Integer, default=0, doc='累计点赞人数')
    read_count = db.Column(db.Integer, default=0, doc='累计阅读人数')

    account = db.Column(db.String(32), doc='账号', unique=True)
    email = db.Column(db.String(64),nullable=True, doc='邮箱')
    status = db.Column(db.Integer, default=1, doc='状态，1可用0不可用是否可用')
    superuser = db.Column(db.Integer, default=0, doc='0普通用户 1 管理员 2 超级管理员')

    news = db.relationship('News', backref="news")
    comment = db.relationship('Comment', backref=db.backref('comments'))
    search = db.relationship('SearchHistory', backref=db.backref('searches'))




 # 用户关注用户 关系表
class Relation(db.Model):
    __tablename__= 'relation_tb'
    user_id = db.Column(db.Integer, db.ForeignKey("user_basic_tb.uid"), primary_key=True)
    foller_id = db.Column(db.Integer, db.ForeignKey("user_basic_tb.uid"), primary_key=True)
    relation = db.Column(db.Boolean, doc='状态(1,关注;0, 取消)')
    create_time = db.Column(db.DateTime, default=datetime.now, doc='创建时间')
    update_time = db.Column(db.DateTime, default=datetime.now, onupdate=datetime.now, doc='更新时间')
    user = db.relationship('User', foreign_keys=user_id)
    foller = db.relationship('User', foreign_keys=user_id)




# 用户关系表
class UserChannel(db.Model):
    __tablename__ = 'user_channel_tb'
    uid = db.Column(db.Integer, db.ForeignKey('user_basic_tb.uid'), primary_key=True, doc="用户ID")
    cid = db.Column(db.Integer, db.ForeignKey('news_channel_tb.cid'), primary_key=True, doc="频道ID")
    is_delete = db.Column(db.Boolean, default=0, doc="状态(0, 可用;1, 不可用)")
    create_time = db.Column(db.DateTime, default=datetime.now, doc="创建时间")
    update_time = db.Column(db.DateTime, default=datetime.now, doc="更新时间")
    sequence = db.Column(db.Integer, default=0, doc='序号')

